<header>
    <title>品牌{notempty name="list"}修改{else /}添加{/notempty}</title>
</header>
{include file="public/header" /}
<br>
<form class="layui-form" action="" method="post">
    {notempty name='list'}<input type="hidden" name="id" value="{$list.id}">{/notempty}

    <div class="layui-form-item">
        <label class="layui-form-label">品牌名称</label>
        <div class="layui-input-block">
            <input style="width: 240px" type="text" value="{notempty name='list'}{$list.brand_name}{/notempty}" name="brand_name" required  lay-verify="required" placeholder="请输入品牌名称" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input style="width: 240px"  value="{notempty name='list'}{$list.sort}{/notempty}"  type="text" name="sort" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="0" title="启用" {notempty name='list'}{if $list['status']==0}checked{/if}{else /}checked{/notempty}>
            <input type="radio" name="status" value="1" title="未启用" {notempty name='list'}{if $list['status']==1}checked{/if}{/notempty}>
        </div>
    </div>

    <div class="layui-upload" style="margin-left: 100px">
        <button type="button" class="layui-btn" id="test1">{notempty name='list'}修改{else /}上传{/notempty}LOGO</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" {notempty name='list'}src="{$list.logo}"{/notempty} hight="200" width="200" id="demo1">
            <p id="demoText"></p>
        </div>
    </div>

    <input type="hidden" id="img" name="logo" value="">

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">品牌描述</label>
        <div class="layui-input-block">
            <textarea name="describe"  placeholder="请输入描述" class="layui-textarea">{notempty name='list'}{$list.describe}{/notempty}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script>


    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            // layer.msg(JSON.stringify(data.field));
            // return false;
        });
    });
</script>

<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '/brands/update' //改成您自己的上传接口
            ,method: 'post'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }else if(res.code == 0){
                    $("#img").val(res.msg);
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

    });
</script>


{include file="public/footer" /}